package com.jintian.smart.kernel.switching.db;

import com.thoughtworks.xstream.annotations.*;
import jakarta.xml.bind.annotation.*;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 采集的数据表
 */
@Data
@XStreamAlias("table")
@XmlRootElement(name = "table")
@XmlAccessorType(XmlAccessType.FIELD)
public class ExtractTable implements Serializable {

    public enum Cascade {
        NONE, DELETE, SETNULL
    }

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    @XStreamAsAttribute
    @XmlAttribute
    private String name;
    @XStreamAsAttribute
    @XmlAttribute
    private String title;
    @XStreamAsAttribute
    @XStreamAlias("class")
    @XmlAttribute(name = "class")
    private String clazz;
    @XStreamAsAttribute
    @XmlAttribute
    private String sqlId;
    @XStreamAsAttribute
    @XmlAttribute
    private int minOccurs = 0;
    @XStreamAsAttribute
    @XmlAttribute
    private int maxOccurs = -1;

    /**
     * 逻辑外键，仅模板加载方式有效。格式为thisField1=parentField1;thisField2=parentField2;...
     */
    @XStreamAsAttribute
    @XmlAttribute
    private String foreignKey;

    @XStreamAsAttribute
    @XmlAttribute
    private boolean loadDeleted;

    @XStreamAsAttribute
    @XmlAttribute
    @XStreamConverter(com.thoughtworks.xstream.converters.enums.EnumConverter.class)
    private Cascade cascade = Cascade.NONE;

    @XStreamAlias("table")
    @XStreamImplicit(itemFieldName = "table")
    @XStreamContainedType
    @XmlElements({@XmlElement(name = "table", type = ExtractTable.class)})
    private List<ExtractTable> children = new ArrayList<>();
}
